home *** CD-ROM | disk | FTP | other *** search
- ;Listing 2- System Definitions
- ;(C) Copyright 1986 Ken Berry.
- ;All rights reserved.
- ;Copies may be made for non-commercial, private use only.
-
-
- sys_parm struc ;; register storage block
- rax dw ? ;; ax (general register A)
- rbx dw ? ;; bx (general register B)
- rcx dw ? ;; cx (general register C)
- rdx dw ? ;; dx (general register D)
- rbp dw ? ;; bp (base pointer)
- rsi dw ? ;; si (source index)
- rdi dw ? ;; di (destination index)
- rsp dw ? ;; sp (stack pointer)
- rcs dw ? ;; cs (code segment)
- rds dw ? ;; ds (data segment)
- rss dw ? ;; ss (stack segment)
- res dw ? ;; es (extra segment)
- rpf dw ? ;; pf (processor flags)
- rsw dw ? ;; sw (status word)
- rip dw ? ;; ip (instruction pointer)
- rres dw ? ;; unused
- sys_parm ends
-
- t_task struc ;; task control table
- t_type db ? ;; task type
- t_wttk dw ? ;; wait tick count
- t_cls dw ? ;; priority queue index
- t_pqtsk dw ? ;; prior t_task pointer
- t_nqtsk dw ? ;; next t_task pointer
- t_ratsk dw ? ;; ancestor t_task pointer
- t_pstsk dw ? ;; prior sibling t_task pointer
- t_nstsk dw ? ;; next sibling t_task pointer
- t_fdtsk dw ? ;; first desendant t_task pointer
- t_ldtsk dw ? ;; last desendant t_task pointer
- t_ps db type sys_parm dup (?) ;; processor status
- t_xtm0 dw ? ;; * execution time accumulator
- t_xtm1 dw ? ;; *
- t_xtm2 dw ? ;; *
- t_axstk dw ? ;; application stack pointer
- t_task ends
-
- T_ATSK equ 01h ;; abreviated task
- T_X equ 80h ;; execute wueue
- T_W equ 40h ;; wait queue
- T_P equ 20h ;; priority queue
- t_SW equ 10h ;; secondary wait queue
-
- t_scls struc ;; scheduling class queue
- t_sfrq dw ? ;; scheduling frequency
- t_sct dw ? ;; queue length
- t_fqtsk dw ? ;; first task in queue
- t_lqtsk dw ? ;; last task in queue
- t_scls ends
-
- t_schd struc ;; scheduling control table
- t_xct dw ? ;; execution queue length
- t_fxtsk dw ? ;; first task in execution queue
- t_lxtsk dw ? ;; last task in execution queue
- t_wct dw ? ;; wait queue length
- t_fwtsk dw ? ;; first task in wait queue
- t_lwtsk dw ? ;; last task in wait queue
- t_swct dw ? ;; secondary wait queue length
- t_fswtsk dw ? ;; first task in secondary wait queue
- t_lswtsk dw ? ;; last task in secondary wait queue
- t_sclsl dw ? ;; scheduling class index limit
- t_sclsp dw ? ;; scheduling class array pointer
- t_schd ends
-
- t_calln struc ;; near function call
- t_nbp dw ? ;; base pointer storage
- t_nret dw ? ;; return address
- t_np0 dw ? ;; parameter 0
- t_np1 dw ? ;; parameter 1
- t_np2 dw ? ;; parameter 2
- t_np3 dw ? ;; parameter 3
- t_np4 dw ? ;; parameter 4
- t_np5 dw ? ;; parameter 5
- t_np6 dw ? ;; parameter 6
- t_np7 dw ? ;; parameter 7
- t_calln ends
-
- t_xtsk struc ;; execution stack
- t_xbase dw ? ;; _base (for stack overflow detection)
- t_xes dw ? ;; es
- t_xbp dw ? ;; bp
- t_xdi dw ? ;; di
- t_xsi dw ? ;; si
- t_xdx dw ? ;; dx
- t_xcx dw ? ;; cx
- t_xbx dw ? ;; bx
- t_xax dw ? ;; ax
- t_xds dw ? ;; ds
- t_xip dw ? ;; ip
- t_xcs dw ? ;; cs
- t_xpf dw ? ;; pf
- t_retip dw ? ;; return ip
- t_xtsk ends
-
- retn macro s ;; near return
- ifnb <s>
- db 0C2h ;; pop ip & adjust sp
- db high s ;; * adjustment value
- db low s ;; *
- else
- db 0C3h ;; pop ip only
- endif
- endm
-
- retf macro s ;; far return
- ifnb <s>
- db 0CCh ;; pop ip, cs & adjust sp
- db high s ;; * adjustment value
- db low s ;; *
- else
- db 0CBh ;; pop ip, cs only
- endif
- endm
-
- ilck macro reg,flag
- xchg reg,flag ;; capture token
- endm
-
- iowait macro
- nop ;; I/O delay
- endm
-
- sys_entr macro flag ;; enter system function
- ifndef sys_ilck
- extrn sys_ilck:byte
- endif
- mov al,0FFh ;; ** system task interlock
- ilck al,sys_ilck ;; **
- mov flag,al ;; save asynchronous status
- endm
-
- sys_exit macro flag ;; exit from system function
- local exit1,exit2
- ifndef sys_ilck
- extrn sys_ilck:byte
- endif
- ifndef t_astrm
- extrn t_astrm:byte
- endif
- ifndef t_term
- extrn t_term:near
- endif
- test byte ptr t_astrm,0FFh ;; * test for application terminated
- jnz exit1 ;; *
- mov byte ptr sys_ilck,0 ;; exit system state
- jmp short exit2 ;; continue application task
- exit1: test flag,0FFH ;; ** test for more stacked system tasks
- jnz exit2 ;; **
- call t_term ;; terminate application task
- exit2: ;; macro exit
- endm
-
- sys_sync macro flag ;; synchronize system resource
- ifndef t_sync
- extrn t_sync:near
- endif
- lea bx,flag ;; set flag offset
- call t_sync ;; suspend task until token obtained
- endm
-
- sys_sstk macro ;; conditionally establish system stack
- local sstk1
- ifndef t__sstk
- extrn t__sstk:near
- endif
- or al,al ;; * test for system task interrupted
- jnz sstk1 ;; *
- call t__sstk ;; establish system stack
- sstk1: push ds ;; ** set es = ds
- pop es ;; **
- endm
-
- sys_sctx macro ;; save processor context
- push bx ;; protect bx
- push cx ;; protect cx
- push dx ;; protect dx
- push si ;; protect si
- push di ;; protect di
- push bp ;; protect bp
- push es ;; protect es
- cld ;; clear direction flag
- sys_sstk ;; conditionally establish system stack
- endm
-
- sys__rctx macro ;; restore processor context (except ds)
- pop es ;; restore es
- pop bp ;; restore bp
- pop di ;; restore di
- pop si ;; restore si
- pop dx ;; restore dx
- pop cx ;; restore cx
- pop bx ;; restore bx
- pop ax ;; restore ax
- endm
-
- sys_rctx macro ;; restore processor context
- sys__rctx ;; restore context (except ds)
- pop ds ;; restore ds
- endm
-
- sys_ient macro flag
- push ds ;; protect ds
- push ax ;; protect ax
- mov ax,dgroup ;; * establish data addressability
- mov ds,ax ;; *
- sys_entr flag ;; enter system state
- sti ;; interrupts on
- sys_sctx ;; save processor context
- endm
-
- sys_iret macro flag
- local iret1
- ifndef t_astrm
- extrn t_astrm:byte
- endif
- cli ;; interrupts off
- test byte ptr t_astrm,0FFh ;; * test for application not terminated
- jz iret1 ;; *
- test flag,0FFh ;; ** test for system state interrupted
- jnz iret1 ;; **
- sti ;; interrupts on
- retn ;; return to task management
- iret1: sys_rctx ;; restore processor context
- iret ;; resume interrupted task
- endm
-
- dseg macro
- dgroup group data
- data segment word public 'data'
- assume ds:dgroup,es:dgroup,ss:dgroup
- endm
-
- endds macro
- data ends
- endm
-
- pseg macro
- pgroup group prog
- prog segment byte public 'prog'
- assume cs:pgroup
- endm
-
- endps macro
- prog ends
- endm
-